<?php
namespace app\yunda\model;

use think\Model;
use traits\model\SoftDelete;

/**
 * 韵达运费表
 * @package app\yunda\model
 */
class Postage extends Model
{
    use SoftDelete;
    protected $table = 'dp_yd_postage';
    protected $autoWriteTimestamp = true;

    /**
     * @param $sp寄件地区
     * @param $gp收件地区
     * @param int $weight 物品重量
     * @return int  运费
     */
    public function getPostage($sp,$gp,$weight=0)
    {
        $map['sp']=$sp;
        $map['gp']=$gp;
        $row=$this->where($map)->field('head_weight,hw_money,ow_money')->find()->toArray();
        $fee=0;
        if($row) {
            if ($weight <= $row['head_weight']) {
                $fee = $row['hw_money'];
            } else {
                $fee = $row['hw_money'] + ($weight - $row['head_weight']) * $row['ow_money'];
            }
        }
        return $fee;
    }
}
